package damai.web;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
import com.yc.damai.entity.DmProduct;
import com.yc.damai.mapper.DmProductMapper;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class ProductDo {

    @Resource
    DmProductMapper productMapper;

    @RequestMapping("queryHot")
    public List<DmProduct> queryHot() {
        IPage<DmProduct> page = new PageDTO<>(1, 10);
        LambdaQueryWrapper<DmProduct> lqw = new LambdaQueryWrapper<>();
        lqw.eq(DmProduct::getIsHot, 1);
        return productMapper.selectPage(page, lqw).getRecords();
    }

    @RequestMapping("queryNew")
    public List<DmProduct> queryNew() {
        IPage<DmProduct> page = new PageDTO<>(1, 10);
        page.orders().add(new OrderItem("id", false));
        return productMapper.selectPage(page, null).getRecords();
    }
}
